<%@ page language="java" isELIgnored="false" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="com.tistory.admin.adminmgr.auth.model.AdminAuthSession" %>
<%@ page import="com.tistory.admin.adminmgr.auth.model.AdminAuthMgr" %>
<%@ page import="com.tistory.admin.common.Constants" %>
<%@ page import="org.apache.log4j.Logger"%>
<%@ page import="java.util.*" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<div class="lnb_area">
 
<%
	Logger log	= Logger.getLogger( "com.omp.admin.adminmgr.auth.adminLeftMenu" );
	AdminAuthSession adminSes	= (AdminAuthSession)request.getSession().getAttribute( Constants.ADMIN_AUTH_SESSION_KEY );
//	String topMenuCode	= request.getParameter( "topCode" );
//	String leftMenuCode	= request.getParameter( "leftCode" );

	//application 의 값을 사용.
	String topMenuCode	= (String)session.getAttribute( "topMenuCode" );
	String leftMenuCode	= (String)session.getAttribute( "leftMenuCode" );

	if ( topMenuCode != null || leftMenuCode != null )	{
		Map map	= adminSes.getMenuListMap();
		List depth2List	= (List)map.get( "ROOT" );

		for( int k = 0; k < depth2List.size(); k++ )	{
		    AdminAuthMgr authMgr2	= (AdminAuthMgr)depth2List.get( k );

		    if ( authMgr2.getMenuId().equals( topMenuCode ) )	{
		        String menuName2	= authMgr2.getMenuName();
		        out.println( "<h2>" + menuName2 + "</h2>" );

//		    	log.info( "[authMgr2.getMenuId()] : [" + authMgr2.getMenuId() + "]" );
//		    	log.info( "[menuName2] : [" + menuName2 + "]" );

		        List depth3list	= (List)map.get( topMenuCode );

				for( int i = 0; i < depth3list.size(); i++ )	{
					AdminAuthMgr authMgr3	= (AdminAuthMgr)depth3list.get( i );
	
					String menuCode3	= authMgr3.getMenuId();
					String menuName3	= authMgr3.getMenuName();
					String url3	= authMgr3.getPageUrl();
					out.println( "<dl class=\"lnb\">" );	  
					out.println( "<dt>&#45;" + menuName3 + "</dt>" );
/*
					log.info( "[menuCode3] : [" + menuCode3 + "]" );
					log.info( "[menuName3] : [" + menuName3 + "]" );
					log.info( "[url3] : [" + url3 + "]" );
*/
					List depth4list	= (List)map.get( menuCode3 );

					out.println( "<dd>" );
					out.println( "<ul class=\"lnb\">" );

					if ( menuCode3.equals( "M003003" ) )	{	// FAQ
						String faqWebURL	= null;
						String faqWebMenuName	= null;

						faqWebURL	= ( (AdminAuthMgr)depth4list.get( 0 ) ).getPageUrl();
						faqWebMenuName	= "FAQ";

						if ( faqWebURL.indexOf( "?" ) > 0 )	{
							faqWebURL	+= "&topCode=" + topMenuCode;
						}	else	{
							faqWebURL	+= "?topCode=" + topMenuCode;
						}
						faqWebURL	+= "&leftCode=" + ( (AdminAuthMgr)depth4list.get( 0 ) ).getMenuId();

//						log.info( "[faqWebURL] : [" + faqWebURL + "]" );
//						log.info( "[faqWebMenuName] : [" + faqWebMenuName + "]" );

						if ( leftMenuCode.equals( "M003003001" ) 
								|| leftMenuCode.equals( "M003003002" ) 
								|| leftMenuCode.equals( "M003003003" ) )	{
							out.println( "<li><b><a href='" + faqWebURL + "'>&#45; " + faqWebMenuName + " * </a></b></li>" );
						}	else	{
							out.println( "<li><a href='" + faqWebURL + "'>&#45; " + faqWebMenuName + "</a></li>" );
						}
					}	else if ( menuCode3.equals( "M003002" ) )	{	// NOTICE
						String noticeWebURL	= null;
						String noticeWebMenuName = null;
						String noticeWebMenuId = null;
						
						/* 2012-07-06 bbj 공지사항 메뉴 하드코딩으로 인한 버그 수정*/
						//noticeWepURL	= ( (AdminAuthMgr)depth4list.get( 0 ) ).getPageUrl();
						for(int j=0; j<depth4list.size(); j++){
							/* 권한이 있는경우에만 noticeWepURL, noticeWepMenuId 셋팅 */
							if( ( (AdminAuthMgr)depth4list.get( j ) ).getMenuId().equals("M003002001") ||
									( (AdminAuthMgr)depth4list.get( j ) ).getMenuId().equals("M003002002") ||
									( (AdminAuthMgr)depth4list.get( j ) ).getMenuId().equals("M003002003") || 
									( (AdminAuthMgr)depth4list.get( j ) ).getMenuId().equals("M003002006") ){
								noticeWebURL	= ( (AdminAuthMgr)depth4list.get( j ) ).getPageUrl();
								noticeWebMenuId	= ( (AdminAuthMgr)depth4list.get( j ) ).getMenuId();
								break;
							}
						}
						
						/* 웹 공지사항 권한이 없는 경우에는 레프트 메뉴에 표시하지 않음. */
						if (noticeWebURL != null){
							noticeWebMenuName = "Web공지사항";
							if ( noticeWebURL.indexOf( "?" ) > 0 )	{
								noticeWebURL	+= "&topCode=" + topMenuCode;
							}	else	{
								noticeWebURL	+= "?topCode=" + topMenuCode;
							}
							/* 2012-07-06 bbj 공지사항 메뉴 하드코딩으로 인한 버그 수정*/
							//noticeWebURL	+= "&leftCode=" + ( (AdminAuthMgr)depth4list.get( 0 ) ).getMenuId();
							noticeWebURL	+= "&leftCode=" + noticeWebMenuId;
		
							if ( leftMenuCode.equals( "M003002001" ) 
									|| leftMenuCode.equals( "M003002002" ) 
									|| leftMenuCode.equals( "M003002003" ) 
									|| leftMenuCode.equals( "M003002006" ) )	{
								out.println( "<li><b><a href='" + noticeWebURL + "'>&#45; " + noticeWebMenuName + " * </a></b></li>" );
							}	else	{
								out.println( "<li><a href='" + noticeWebURL + "'>&#45; " + noticeWebMenuName + "</a></li>" );
							}
						}
						
						
						String noticeWapURL	= null;
						String noticeWapMenuName	= null;
						String noticeWapMenuId = null;
						
						/* 2012-07-06 bbj 공지사항 메뉴 하드코딩으로 인한 버그 수정*/
						//noticeWapURL	= ( (AdminAuthMgr)depth4list.get( 3 ) ).getPageUrl();
						for(int j=0; j<depth4list.size(); j++){
							/* 권한이 있는경우에만 noticeWapURL, noticeWapMenuId 셋팅 */
							if( ( (AdminAuthMgr)depth4list.get( j ) ).getMenuId().equals("M003002004") || ( (AdminAuthMgr)depth4list.get( j ) ).getMenuId().equals("M003002005")){
								noticeWapURL	= ( (AdminAuthMgr)depth4list.get( j ) ).getPageUrl();
								noticeWapMenuId	= ( (AdminAuthMgr)depth4list.get( j ) ).getMenuId();
								break;
							}
						}
						
						/* 모바일 공지사항 권한이 없는 경우에는 레프트 메뉴에 표시하지 않음. */
						if(noticeWapURL != null){
							noticeWapMenuName	= "모바일 공지사항";
	
							if ( noticeWapURL.indexOf( "?" ) > 0 )	{
								noticeWapURL	+= "&topCode=" + topMenuCode;
							}	else	{
								noticeWapURL	+= "?topCode=" + topMenuCode;
							}
							/* 2012-07-06 bbj 공지사항 메뉴 하드코딩으로 인한 버그 수정*/
							//noticeWapURL	+= "&leftCode=" + ( (AdminAuthMgr)depth4list.get( 3 ) ).getMenuId();
							noticeWapURL	+= "&leftCode=" + noticeWapMenuId;
	
							if ( leftMenuCode.equals( "M003002004" )
									|| leftMenuCode.equals( "M003002005" )  )	{
								out.println( "<li><b><a href='" + noticeWapURL + "'>&#45; " + noticeWapMenuName + " * </a></b></li>" );
							}	else	{
								out.println( "<li><a href='" + noticeWapURL + "'>&#45; " + noticeWapMenuName + "</a></li>" );
							}
						}
					}	else	{	// Another
						for( int j = 0; j < depth4list.size(); j++ )	{			    
							AdminAuthMgr authMgr4	= (AdminAuthMgr)depth4list.get( j );
							String menuCode4	= authMgr4.getMenuId();
							String menuName4	= authMgr4.getMenuName();

							String auth4url	= authMgr4.getPageUrl();
							StringBuffer sb	= new StringBuffer();
/*
							log.info( "[menuCode4] : [" + menuCode4 + "]" );
							log.info( "[menuName4] : [" + menuName4 + "]" );
							log.info( "[auth4url] : [" + auth4url + "]" );
*/
							if ( auth4url.indexOf( "?" ) > 0 )	{
								sb.append( auth4url ).append( "&topCode=" ).append( topMenuCode );
							}	else	{
								sb.append( auth4url ).append( "?topCode=" ).append( topMenuCode );
							}
							sb.append( "&leftCode=" ).append( authMgr4.getMenuId() );

							String url4	= sb.toString();
//							log.info( "[url4] : [" + url4 + "]" );

							if ( leftMenuCode.equals( authMgr4.getMenuId() ) )	{
								out.println( "<li><b><a href='" + url4 + "'>&#45; " + menuName4 + " * </a></b></li>" );
							}	else	{
								out.println( "<li><a href='" + url4 + "'>&#45; " + menuName4 + "</a></li>" );
							}

//							log.info( "[authMgr4.getMenuId()] : [" + authMgr4.getMenuId() + "]" );
						}	// end for
					}

					out.println( "</ul>" );
					out.println( "</dd>" );
					out.println( "</dl>" );
				}	// end for
			}	// end if
		}	// end for
	}	// end if
%>

</div>
